SearchPageManager=function(){
	this.inited=false;
	this.shiwenListLoader=null;
	this.writerListLoader=null;
}

SearchPageManager.defValue={
	shiciSearchContent:"#shici-search-content",
	shiwenScrollConfig:{
	   el:"#xq-shiwen-result-scroll-wrapper",
	   up:{
		   initLoadOnce:false,
			loadFunction:function(manager){
				manager.loadShiwenList();
			}
	   }
	},
	shiwenListLoaderConfig:{
		appVMConfig:{el:'#shiwen-result-list-ul'},
		itemContentEl:"#shiwen-result-list-ul",
		loadParam:{pageNo:1}
	},
	writerScrollConfig:{
	   el:"#xq-writer-result-scroll-wrapper",
	   up:{
		   initLoadOnce:false,
			loadFunction:function(manager){
				manager.loadWriterList();
			}
	   }
	},
	writerListLoaderConfig:{
		appVMConfig:{el:'#writer-result-list-ul'},
		itemContentEl:"#writer-result-list-ul",
		loadParam:{pageNo:1}
	}
}

SearchPageManager.prototype.init=function(opts){
	var that=this;
	if(!this.inited){
		this.options=$.extend(true,{},SearchPageManager.defValue,opts);
		//
		this.shiwenListLoader=new ShiwenListLoader();
		this.options.shiwenListLoaderConfig.loadOverCallback=function(loader,data){
			that.shiwenScroll.loadOver(data.entry.hasNextPage);
		}
		this.shiwenListLoader.init(this.options.shiwenListLoaderConfig);
		//
		var shiwenScrollConfig=this.options.shiwenScrollConfig;
		var configUpFunction=shiwenScrollConfig.up.loadFunction;
		shiwenScrollConfig.up.loadFunction=function(){
			configUpFunction(that);
		}
		this.shiwenScroll=new RefreshAbleScroll(shiwenScrollConfig.el,shiwenScrollConfig);
		this.shiwenScroll.resetUpEnabled({enabled:false,textShowStatus:'hidden'});
		//
		this.writerListLoader=new WriterListLoader();
		this.options.writerListLoaderConfig.loadOverCallback=function(loader,data){
			that.writerScroll.loadOver(data.entry.hasNextPage);
		}
		this.writerListLoader.init(this.options.writerListLoaderConfig);
		//
		var writerScrollConfig=this.options.writerScrollConfig;
		var writerConfigUpFunction=writerScrollConfig.up.loadFunction;
		writerScrollConfig.up.loadFunction=function(){
			writerConfigUpFunction(that);
		}
		this.writerScroll=new RefreshAbleScroll(writerScrollConfig.el,writerScrollConfig);
		this.writerScroll.resetUpEnabled({enabled:false,textShowStatus:'hidden'});
		//this.loadShiwenList();
		this.resetEleSize();
		this.registerEvent();
		//
		var shiciSearchContent=this.options.shiciSearchContent;
		//$(shiciSearchContent+" input").trigger("focus");
	}
	this.inited=true;
}

SearchPageManager.prototype.loadShiwenList=function(){
	var loadParam=this.shiwenListLoader.getLoadParam();
	//loadParam.tagId=this.tagId;
	this.shiwenListLoader.loadShiwenList();
	loadParam.pageNo++;
}

SearchPageManager.prototype.loadWriterList=function(){
	var loadParam=this.writerListLoader.getLoadParam();
	//loadParam.tagId=this.tagId;
	this.writerListLoader.loadWriterList();
	loadParam.pageNo++;
}

SearchPageManager.prototype.registerEvent=function(){
	var that=this;
	var shiciSearchContent=this.options.shiciSearchContent;
	// 搜索事件,获取搜索关键词
	$(shiciSearchContent+' input').on("keyup",function(e){
		if(e.keyCode == 13) {//用户点击回车的事件号为13
			var keyword = $(shiciSearchContent+' input').val();
			document.activeElement.blur();//收起虚拟键盘
			//
			var loadParam=that.shiwenListLoader.getLoadParam();
			loadParam.pageNo=1;
			loadParam.titleTypeContent=keyword;
			that.shiwenListLoader.emptyShiwenList();
			that.shiwenScroll.resetUpEnabled({enabled:true,textShowStatus:'show'});
			that.shiwenScroll.reInit();
			that.loadShiwenList();
			//
			var writerLoadParam=that.writerListLoader.getLoadParam();
			writerLoadParam.pageNo=1;
			writerLoadParam.name=keyword;
			that.writerListLoader.emptyWriterList();
			that.writerScroll.resetUpEnabled({enabled:true,textShowStatus:'show'});
			that.writerScroll.reInit();
			that.loadWriterList();
		}
	});
	//
	$(shiciSearchContent+' .mui-icon-clear').on('tap',function(e){
		console.log("mui-icon-clear")
		that.shiwenListLoader.emptyShiwenList();
		that.shiwenScroll.resetUpEnabled({enabled:false,textShowStatus:'hidden'});
		that.shiwenScroll.reInit();
		//
		that.writerListLoader.emptyWriterList();
		that.writerScroll.resetUpEnabled({enabled:false,textShowStatus:'hidden'});
		that.writerScroll.reInit();
	});
	
}

SearchPageManager.prototype.resetEleSize=function(){
	var that=this;
	var shiciSearchContent=this.options.shiciSearchContent;
	var winW=$(window).width();
	
	var searchW=winW-50;
	$(shiciSearchContent).css('width',searchW+'px');
	var winH=$(window).height();
	var sliderH=winH-88;
	$(".mui-slider-item").css('height',sliderH+'px');
}